package cn.yunhe.controller;

import cn.yunhe.entity.Exam;
import cn.yunhe.entity.ExamPaper;
import cn.yunhe.entity.User;
import cn.yunhe.service.ExamPaperService;
import cn.yunhe.service.ExamService;
import cn.yunhe.util.DateUtil;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController

public class ExamController {
    @Autowired
    @Qualifier("examService")
    private ExamService examService;
    @Resource
    private ExamPaperService examPaperService;

    @RequestMapping("/exam")
    public ModelAndView getExamList1() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("exam");
        return mv;
    }

    @RequestMapping("/getexamlist")
    public List<Exam> getExamList() {
        List<Exam> examList = examService.getExamList();
        return examList;
    }

    @RequestMapping("/getexamination")
    public List<Exam> getExamination() {
        List<Exam> examList = examService.getExamination();
        return examList;

    }

    /***
     * 获取所有可申请的考试
     * @return
     */
    @RequestMapping("/getapplytest")
    public List<Exam> getApplyTest(HttpSession session) {
        examService.updAllExamAudit();
        User user = (User) session.getAttribute("Curr_User");
        List list = examService.getApplyTest(user.getUserId());
        return examService.getApplyTest(user.getUserId());
    }

    @RequestMapping("/getCurrUserExam")
    public List<Map<String, Object>> getCurrUserExam(HttpSession session) {
        User user = (User) session.getAttribute("Curr_User");
        return examService.getCurrUserExam(user.getUserId());
    }

    /***
     * 获取我的考试
     * @return
     */
    @RequestMapping("/getExamListToApply")
    public List<Exam> getExamListToApply(HttpSession session) {
        User user = (User) session.getAttribute("Curr_User");
        List<Exam> getExamListToApply = examService.getExamListToApply(user.getUserId());
        return getExamListToApply;
    }


    @RequestMapping("/updExamAudit")
    public int updExamAudit(Exam exam) {
        return examService.updExamAudit(exam);
    }

    @RequestMapping("/addApply")
    public int addApply(int examId, HttpSession session) {
        User user = (User) session.getAttribute("Curr_User");
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("examId", examId);
        map.put("userId", user.getUserId());
        return examService.addApply(map);
    }

    @RequestMapping("/getAllSimulate")
    public List<Exam> getAllSimulate() {
        List list = examService.getAllSimulate();
        return list;
    }

    public ExamService getExamService() {
        return examService;
    }

    public void setExamService(ExamService examService) {
        this.examService = examService;
    }

    public ExamPaperService getExamPaperService() {
        return examPaperService;
    }

    public void setExamPaperService(ExamPaperService examPaperService) {
        this.examPaperService = examPaperService;
    }
}
